package hku.cs.lunuo.voter.impl;

import hku.cs.lunuo.rank.DefaultLabel;
import hku.cs.lunuo.rank.model.Label;
import hku.cs.lunuo.voter.VotedGlobal;
import hku.cs.lunuo.voter.VotedUnit;
import hku.cs.lunuo.voter.Voter;

public class O2Minos extends Voter {

	@Override
	public Label vote(VotedUnit u, VotedGlobal g) {
		int falseCases = u.tf.getFlsTimes();
		int trueCases = u.tf.getTruTimes();
		float susc, noise;

		susc = (float) (falseCases*(g.totalTF.getTruTimes()-trueCases) / 
				Math.sqrt(
				(falseCases + trueCases)
				*(g.totalTF.getTruTimes()-trueCases+g.totalTF.getFlsTimes()-falseCases)
				*(falseCases+g.totalTF.getFlsTimes()-falseCases)
				*(trueCases+g.totalTF.getTruTimes()-trueCases)));
		
		if(g.totalTF.getFlsTimes()==falseCases)
			noise = 0;
		else
			noise = (float) (
					(g.totalTF.getFlsTimes()-falseCases)* trueCases
					/ 
					Math.sqrt(
							(falseCases + trueCases)
							*(g.totalTF.getTruTimes()-trueCases+g.totalTF.getFlsTimes()-falseCases)
							*(falseCases+g.totalTF.getFlsTimes()-falseCases)
							*(trueCases+g.totalTF.getTruTimes()-trueCases)));
		return new DefaultLabel(susc-noise);
	}

}
